package com.investment.advisor.repository;

import com.investment.advisor.entity.PortfolioFund;
import com.investment.advisor.entity.Portfolio;
import com.investment.advisor.entity.Fund;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

public interface PortfolioFundRepository extends JpaRepository<PortfolioFund, Long> {
    List<PortfolioFund> findByPortfolio(Portfolio portfolio);
    
    List<PortfolioFund> findByFund(Fund fund);
    
    PortfolioFund findByPortfolioAndFund(Portfolio portfolio, Fund fund);
    
    @Modifying
    @Query("DELETE FROM PortfolioFund pf WHERE pf.portfolio.id = :portfolioId")
    void deleteByPortfolioId(@Param("portfolioId") Long portfolioId);
    
    @Modifying
    @Query("DELETE FROM PortfolioFund pf WHERE pf.portfolio.id = :portfolioId AND pf.fund.id = :fundId")
    void deleteByPortfolioIdAndFundId(@Param("portfolioId") Long portfolioId, @Param("fundId") Long fundId);
} 